#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

void addr()
{
	char da[5][4];

	printf(" offset of [0][0] in [5][4] is %ld \n", (intptr_t)(&da[0][0]) - (intptr_t)da);
	printf(" offset of [0][1] in [5][4] is %ld \n", (intptr_t)(&da[0][1]) - (intptr_t)da);
	printf(" offset of [1][0] in [5][4] is %ld \n", (intptr_t)(&da[1][0]) - (intptr_t)da);
	printf(" offset of [1][1] in [5][4] is %ld \n", (intptr_t)(&da[1][1]) - (intptr_t)da);
	printf(" offset of [3][2] in [5][4] is %ld \n", (intptr_t)(&da[3][2]) - (intptr_t)da);

	char ta[5][4][3];

	printf(" offset of [0][0][0] in [5][4][3] is %ld \n", (intptr_t)(&ta[0][0][0]) - (intptr_t)ta);
	printf(" offset of [0][0][1] in [5][4][3] is %ld \n", (intptr_t)(&ta[0][0][1]) - (intptr_t)ta);
	printf(" offset of [0][1][0] in [5][4][3] is %ld \n", (intptr_t)(&ta[0][1][0]) - (intptr_t)ta);
	printf(" offset of [1][0][0] in [5][4][3] is %ld \n", (intptr_t)(&ta[1][0][0]) - (intptr_t)ta);
	printf(" offset of [1][1][1] in [5][4][3] is %ld \n", (intptr_t)(&ta[1][1][1]) - (intptr_t)ta);
};

void josephus(size_t n, size_t m)
{
	int p[n];
	for (size_t i = 0; i < n; ++i) {
		p[i] = i + 1;
	}

	size_t t = 0;

	printf("\n\n");
	for (size_t i = n; i; --i) {
		t = (t + m - 1) % i;
		printf(" %d,", p[t]);
		for (size_t j = t + 1; j <= i - 1; ++j) {
			p[j - 1] = p[j];
		}
	}
	printf("\n\n");
}


